import pygame
from pygame.locals import *

from config import Config
from main import print_text


def restart(screen, event):
    # 设置按钮文字大小，字体，位置
    rect1 = Rect(300, 400, 150, 50)
    pygame.draw.rect(screen, (126, 211, 178), rect1)
    # 设置按钮文字大小，字体，位置
    font = pygame.font.SysFont('SimHei', 20)
    print_text(screen, font, 320, 415, "再来一局(R)")
    if event.type == pygame.MOUSEBUTTONUP and in_button(rect1):
        return True


def exit_game(screen, event):
    # 设置按钮文字大小，字体，位置
    rect1 = Rect(500, 400, 150, 50)
    pygame.draw.rect(screen, (238, 111, 87), rect1)
    # 设置按钮文字大小，字体，位置
    font = pygame.font.SysFont('SimHei', 20)
    print_text(screen, font, 510, 415, "退出游戏(ESC)")
    if event.type == pygame.MOUSEBUTTONUP and in_button(rect1):
        return True


def start_game(screen, event):
    # 设置按钮文字大小，字体，位置
    rect1 = Rect(610, 380, 210, 60)
    pygame.draw.rect(screen, Config.start_game_btn_color, rect1)
    # 设置按钮文字大小，字体，位置
    font = pygame.font.SysFont('SimHei', 20)
    print_text(screen, font, 670, 400, "开始游戏", (255, 255, 255))
    if event.type == pygame.MOUSEBUTTONUP and in_button(rect1):
        return True


def theme1(screen, event):
    color = 188, 186, 184
    # 设置按钮文字大小，字体，位置
    rect1 = Rect(800, 0, 50, 20)
    pygame.draw.rect(screen, (30, 144, 255), rect1)
    # 设置按钮文字大小，字体，位置
    font = pygame.font.SysFont('SimHei', 15)
    print_text(screen, font, 805, 2, "主题1", (255, 255, 255))
    if event.type == pygame.MOUSEBUTTONUP and in_button(rect1):
        color = 80, 80, 80
        # 设置按钮文字大小，字体，位置
        rect1 = Rect(800, 0, 50, 20)
        pygame.draw.rect(screen, color, rect1)
        # 设置按钮文字大小，字体，位置
        font = pygame.font.SysFont('SimHei', 15)
        print_text(screen, font, 805, 2, "主题1", (255, 255, 255))
        return True


def theme2(screen, event):
    color = 188, 186, 184
    # 设置按钮文字大小，字体，位置
    rect1 = Rect(860, 0, 50, 20)
    pygame.draw.rect(screen, color, rect1)
    # 设置按钮文字大小，字体，位置
    font = pygame.font.SysFont('SimHei', 15)
    print_text(screen, font, 865, 2, "主题2")
    if event.type == pygame.MOUSEBUTTONUP and in_button(rect1):

        color = 80, 80, 80
        # 设置按钮文字大小，字体，位置
        rect1 = Rect(860, 0, 50, 20)
        pygame.draw.rect(screen, color, rect1)
        # 设置按钮文字大小，字体，位置
        font = pygame.font.SysFont('SimHei', 15)
        print_text(screen, font, 865, 2, "主题2")
        return True
# 判断鼠标点击是否在按钮内


def in_button(self):
    point_x, point_y = pygame.mouse.get_pos()

    if self.collidepoint(point_x, point_y):
        return True
    else:
        return False
